using FairyGUI;
using FairyGUI.Utils;
using UnityEngine;
using System.IO;
using System.Collections.Generic;
using System;

namespace UIPack
{
    public partial class ComGetItem : GComponent
    {
        private static ComGetItem ins;
        public static ComGetItem Instance
        {
            get
            {
                if (ins == null)
                {
                    ins = CreateInstance();
                    ins.Init();
                }

                return ins;
            }
        }

        private Action cb;
        private void Init() {
            Anim.Stop();

            Btn.onClick.Set((EventContext ctx) => {

                Pop.RemovePop(this);

                if (cb != null)
                    cb();
            });
        }

        public void SetContent(string itemId, Action clickOkHandle = null) {
            var item = Config.ItemCfg[itemId];
            Ld.url = $"ui://UIPack/{Config.ItemCfg[itemId].resName}";
            Txt.text = $"获得“{item.name}”";

            this.cb = clickOkHandle;
        }

        public void PlayAnim() {
            Anim.Play();
        }
    }
}